public class Painting {
	public int largestBrush(String[] picture) {
		int rowCount = picture.length;
		int columnCount = picture[0].length();
		boolean[][] expectedPicture = new boolean[rowCount][columnCount];
		for (int i = 0; i < rowCount; i++) {
			for (int j = 0; j < columnCount; j++)
				expectedPicture[i][j] = picture[i].charAt(j) == 'B';
		}
		for (int i = 2; i <= Math.min(rowCount, columnCount); i++) {
			boolean[][] currentPicture = new boolean[rowCount][columnCount];
			for (int j = 0; j <= rowCount - i; j++) {
				for (int k = 0; k <= columnCount - i; k++) {
					boolean canPaint = true;
					for (int l = j; l < j + i && canPaint; l++) {
						for (int m = k; m < k + i && canPaint; m++) {
							if (!expectedPicture[l][m])
								canPaint = false;
						}
					}
					if (canPaint) {
						for (int l = j; l < j + i && canPaint; l++) {
							for (int m = k; m < k + i && canPaint; m++)
								currentPicture[l][m] = true;
						}
					}
				}
			}
			for (int j = 0; j < rowCount; j++) {
				for (int k = 0; k < columnCount; k++) {
					if (currentPicture[j][k] != expectedPicture[j][k])
						return i - 1;
				}
			}
		}
		return Math.min(rowCount, columnCount);
	}


// BEGIN CUT HERE
	public static void main(String[] args) {
		if (args.length == 0) {
			PaintingHarness.run_test(-1);
		} else {
			for (int i=0; i<args.length; ++i)
				PaintingHarness.run_test(Integer.valueOf(args[i]));
		}
	}
// END CUT HERE
}

// BEGIN CUT HERE
class PaintingHarness {
	public static void run_test(int casenum) {
		if (casenum != -1) {
			if (runTestCase(casenum) == -1)
				System.err.println("Illegal input! Test case " + casenum + " does not exist.");
			return;
		}
		
		int correct = 0, total = 0;
		for (int i=0;; ++i) {
			int x = runTestCase(i);
			if (x == -1) {
				if (i >= 100) break;
				continue;
			}
			correct += x;
			++total;
		}
		
		if (total == 0) {
			System.err.println("No test cases run.");
		} else if (correct < total) {
			System.err.println("Some cases FAILED (passed " + correct + " of " + total + ").");
		} else {
			System.err.println("All " + total + " tests passed!");
		}
	}
	
	static boolean compareOutput(int expected, int result) { return expected == result; }
	static String formatResult(int res) {
		return String.format("%d", res);
	}
	
	static int verifyCase(int casenum, int expected, int received) { 
		System.err.print("Example " + casenum + "... ");
		if (compareOutput(expected, received)) {
			System.err.println("PASSED");
			return 1;
		} else {
			System.err.println("FAILED");
			System.err.println("    Expected: " + formatResult(expected)); 
			System.err.println("    Received: " + formatResult(received)); 
			return 0;
		}
	}

	static int runTestCase(int casenum) {
		switch(casenum) {
		case 0: {
			String[] picture          = {"BBBB",  "BBBB",  "BBBB",  "BBBB"};
			int expected__            = 4;

			return verifyCase(casenum, expected__, new Painting().largestBrush(picture));
		}
		case 1: {
			String[] picture          = {"BBBB",  "BWWB",  "BWWB",  "BBBB"};
			int expected__            = 1;

			return verifyCase(casenum, expected__, new Painting().largestBrush(picture));
		}
		case 2: {
			String[] picture          = {"WBBBBB",  "BBBBBB",  "BBBBBB",  "BBBBBB"} ;
			int expected__            = 3;

			return verifyCase(casenum, expected__, new Painting().largestBrush(picture));
		}
		case 3: {
			String[] picture          = {"BBBB",  "BBBB",  "WBBB",  "BBBB",  "BBBB",  "BBBB"} ;
			int expected__            = 2;

			return verifyCase(casenum, expected__, new Painting().largestBrush(picture));
		}
		case 4: {
			String[] picture          = {"WBBBBBWWWWWWWWW",  "WBBBBBBWWWWWWWW",  "WBBBBBBBBBBBWWW",  "WBBBBBBBBBBBWWW",  "BBBBBBBBBBBBBBB",  "BBBBBBBBBBBBBBB",  "BBBBBBBBBBBBBBB",  "BBBBBBBBWWBBBBB",  "BBBBBBBBWBBBBBB",  "WBBBBBBBWBBBBBW",  "BBBBBBBWWBBBBBW",  "BBBBBBBWWBBBBBW",  "BBBBBBWWWBBBBBW",  "BBBBBWWWWWWWWWW",  "BBBBBWWWWWWWWWW"} ;
			int expected__            = 5;

			return verifyCase(casenum, expected__, new Painting().largestBrush(picture));
		}

		// custom cases

/*      case 5: {
			String[] picture          = ;
			int expected__            = ;

			return verifyCase(casenum, expected__, new Painting().largestBrush(picture));
		}*/
/*      case 6: {
			String[] picture          = ;
			int expected__            = ;

			return verifyCase(casenum, expected__, new Painting().largestBrush(picture));
		}*/
/*      case 7: {
			String[] picture          = ;
			int expected__            = ;

			return verifyCase(casenum, expected__, new Painting().largestBrush(picture));
		}*/
		default:
			return -1;
		}
	}
}

// END CUT HERE
